
ac.loop(1000,function()
    ac.each_player(function(player)
        local hero = player.hero
        local change = player:get_data('累计显示金币',0)
        player:set_data('累计显示金币',0)
        if hero and change>0 then
            ac.texttag {
                text = ('|cffffff00%0.f|n'):format(change),
                font_size = 36,
                angle = 90,
                speed = 100,
                lifespan = 1,
                fadepoint = 0.5,
                target = hero:get_point(),
            }
        end
    end)
end)


local function add_exp(exp)
    local exp = exp / ac.player.online_count
    ac.each_player(function(player)
        local hero = player.hero
        if hero then
            local xp = exp * (1 + hero:get('经验加成')/100)
            hero:add_exp(xp)
            hero:notify('单位-获得经验',hero,xp)
        end
    end)
end

ac.game:event '单位-死亡'(function(_,unit,killer)
    local player = killer.owner
    if not player then
        return
    end
    local hero = player.hero
    if not hero then
        return
    end
    local gold = unit['金币'] or 0
    local exp = unit['经验'] or 0
    local lumber = unit['木材']
    local xd = unit['杀敌'] or 1
    gold = gold + hero:get('杀敌金币')
    hero:notify('英雄-击杀单位',hero,unit)
    add_exp(exp)
    if lumber then
        if type(lumber)=='string' then
            local min,max = lumber:match('(%d*)-(%d*)')
            lumber = math.random(min,max)
        end
        if lumber>0 then
            local owner = unit.owner_player or player
            unit:add_effect([[Abilities\Spells\Items\ResourceItems\ResourceEffectTarget.mdl]]):remove()
            owner:add('木材',lumber)
            owner:send_msg(('获得|cff00ff00%0.f|r木材'):format(lumber))
            ac.ui_tag {
                string = ('|cff00ff00+%0.f|r'):format(lumber),
                speed = 200,
                life = 1,
                fade = 0.5,
                player = player,
                position = unit:get_point(),
                icon = [[图标\木材.blp]],
            }
        end
    end
    if gold>0 then
        player:add('金币',gold)
        ac.ui_tag {
            string = ('|cffffff00+%0.f|r'):format(gold),
            speed = 200,
            life = 1,
            fade = 0.5,
            position = unit:get_point(),
            player = player,
            icon = [[图标\金币.blp]],
        }
    end
    if xd>1 then
        ac.ui_tag {
            string = ('|cffffcc99+%0.f|r'):format(xd),
            speed = 200,
            life = 1,
            fade = 0.5,
            position = unit:get_point(),
            player = player,
            icon = [[图标\杀敌显示.tga]],
        }
    end
    if unit.name=='经验怪' then
        ac.ui_tag {
            string = ('|cffcc99ff+%0.f|r'):format(exp),
            speed = 200,
            life = 1,
            fade = 0.5,
            position = unit:get_point(),
            player = player,
            icon = [[图标\经验.tga]],
        }
    end
    player:add('杀敌',xd)
    player:set_data('累计显示金币',player:get_data('累计显示金币',0) + gold)
    player:set_data('总杀敌',player:get_data('总杀敌',0) + 1)
end)